﻿using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;

namespace Dycox.Workflows.Data
{

    [global::System.Data.Linq.Mapping.DatabaseAttribute(Name = "PDMS3")]
    internal partial class WorkflowDataContext : System.Data.Linq.DataContext
    {

        private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();

        #region Extensibility Method Definitions
        partial void OnCreated();
        partial void InsertWFProcess(Dycox.Workflows.WFProcess instance);
        partial void UpdateWFProcess(Dycox.Workflows.WFProcess instance);
        partial void DeleteWFProcess(Dycox.Workflows.WFProcess instance);
        partial void InsertWFThread(Dycox.Workflows.WFThread instance);
        partial void UpdateWFThread(Dycox.Workflows.WFThread instance);
        partial void DeleteWFThread(Dycox.Workflows.WFThread instance);
        partial void InsertWFStep(Dycox.Workflows.WFStep instance);
        partial void UpdateWFStep(Dycox.Workflows.WFStep instance);
        partial void DeleteWFStep(Dycox.Workflows.WFStep instance);
        partial void InsertWFFrame(Dycox.Workflows.WFFrame instance);
        partial void UpdateWFFrame(Dycox.Workflows.WFFrame instance);
        partial void DeleteWFFrame(Dycox.Workflows.WFFrame instance);
        #endregion

        public WorkflowDataContext() :
            base(global::Dycox.Properties.Settings.Default.PDMS3ConnectionString, mappingSource)
        {
            OnCreated();
        }

        public WorkflowDataContext(string connection) :
            base(connection, mappingSource)
        {
            OnCreated();
        }

        public WorkflowDataContext(System.Data.IDbConnection connection) :
            base(connection, mappingSource)
        {
            OnCreated();
        }

        public WorkflowDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
            base(connection, mappingSource)
        {
            OnCreated();
        }

        public WorkflowDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
            base(connection, mappingSource)
        {
            OnCreated();
        }

        public System.Data.Linq.Table<Dycox.Workflows.WFProcess> WFProcesses
        {
            get
            {
                return this.GetTable<Dycox.Workflows.WFProcess>();
            }
        }

        public System.Data.Linq.Table<Dycox.Workflows.WFThread> WFThreads
        {
            get
            {
                return this.GetTable<Dycox.Workflows.WFThread>();
            }
        }

        public System.Data.Linq.Table<Dycox.Workflows.WFStep> WFSteps
        {
            get
            {
                return this.GetTable<Dycox.Workflows.WFStep>();
            }
        }

        internal System.Data.Linq.Table<Dycox.Workflows.WFFrame> WFFrames
        {
            get
            {
                return this.GetTable<Dycox.Workflows.WFFrame>();
            }
        }
    }
}
namespace Dycox.Workflows
{
    using System.Runtime.Serialization;
    using System.Data.Linq;
    using System.Data.Linq.Mapping;
    using System.ComponentModel;
    using System;
    using System.Security.Cryptography;


    [global::System.Data.Linq.Mapping.TableAttribute(Name = "dbo.wf_Processes")]
    [global::System.Runtime.Serialization.DataContractAttribute()]
    public partial class WFProcess : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        [DataMember]
        private System.Guid _ProcessId;

        [DataMember]
        private string _WorkflowName;

        [DataMember]
        private string _DisplayName;

        [DataMember]
        private System.DateTime _CreationTime;

        [DataMember]
        private System.Nullable<System.DateTime> _StartTime;

        [DataMember]
        private System.Nullable<System.DateTime> _FinishTime;

        [DataMember]
        private System.DateTime _LastActiveTime;

        [DataMember]
        private string _LastStageName;

        [DataMember]
        private WorkflowComponentStatus _Status;

        [DataMember]
        private short _ThreadSeed;

        [DataMember]
        private string _PropertiesData;

        private EntitySet<WFThread> _ThreadsInternal;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnProcessIdChanging(System.Guid value);
        partial void OnProcessIdChanged();
        partial void OnWorkflowNameChanging(string value);
        partial void OnWorkflowNameChanged();
        partial void OnDisplayNameChanging(string value);
        partial void OnDisplayNameChanged();
        partial void OnCreationTimeChanging(System.DateTime value);
        partial void OnCreationTimeChanged();
        partial void OnStartTimeChanging(System.Nullable<System.DateTime> value);
        partial void OnStartTimeChanged();
        partial void OnFinishTimeChanging(System.Nullable<System.DateTime> value);
        partial void OnFinishTimeChanged();
        partial void OnLastActiveTimeChanging(System.DateTime value);
        partial void OnLastActiveTimeChanged();
        partial void OnLastStageChanging(string value);
        partial void OnLastStageChanged();
        partial void OnStatusChanging(WorkflowComponentStatus value);
        partial void OnStatusChanged();
        partial void OnThreadSeedChanging(short value);
        partial void OnThreadSeedChanged();
        partial void OnPropertiesDataChanging(string value);
        partial void OnPropertiesDataChanged();
        #endregion

        public WFProcess()
        {
            this.Initialize();
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_ProcessId", DbType = "UniqueIdentifier NOT NULL", IsPrimaryKey = true)]
        internal System.Guid ProcessId
        {
            get
            {
                return this._ProcessId;
            }
            set
            {
                if ((this._ProcessId != value))
                {
                    this.OnProcessIdChanging(value);
                    this.SendPropertyChanging();
                    this._ProcessId = value;
                    this.SendPropertyChanged("ProcessId");
                    this.OnProcessIdChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_WorkflowName", DbType = "NVarChar(50) NOT NULL", CanBeNull = false)]
        public string WorkflowName
        {
            get
            {
                return this._WorkflowName;
            }
            internal set
            {
                if ((this._WorkflowName != value))
                {
                    this.OnWorkflowNameChanging(value);
                    this.SendPropertyChanging();
                    this._WorkflowName = value;
                    this.SendPropertyChanged("WorkflowName");
                    this.OnWorkflowNameChanged();
                }
            }
        }

        [DataMember]
        private short _StepSeed;

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_StepSeed", DbType = "SmallInt NOT NULL")]
        internal short StepSeed
        {
            get
            {
                return this._StepSeed;
            }
            set
            {
                if ((this._StepSeed != value))
                {
                    this.SendPropertyChanging();
                    this._StepSeed = value;
                    this.SendPropertyChanged("StepSeed");
                }
            }
        }



        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_DisplayName", DbType = "NVarChar(100) NOT NULL", CanBeNull = false)]
        public string DisplayName
        {
            get
            {
                return this._DisplayName;
            }
            internal set
            {
                if ((this._DisplayName != value))
                {
                    this.OnDisplayNameChanging(value);
                    this.SendPropertyChanging();
                    this._DisplayName = value;
                    this.SendPropertyChanged("DisplayName");
                    this.OnDisplayNameChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_CreationTime", DbType = "DateTime NOT NULL")]
        public System.DateTime CreationTime
        {
            get
            {
                return this._CreationTime;
            }
            internal set
            {
                if ((this._CreationTime != value))
                {
                    this.OnCreationTimeChanging(value);
                    this.SendPropertyChanging();
                    this._CreationTime = value;
                    this.SendPropertyChanged("CreationTime");
                    this.OnCreationTimeChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_StartTime", DbType = "SmallDateTime")]
        public System.Nullable<System.DateTime> StartTime
        {
            get
            {
                return this._StartTime;
            }
            internal set
            {
                if ((this._StartTime != value))
                {
                    this.OnStartTimeChanging(value);
                    this.SendPropertyChanging();
                    this._StartTime = value;
                    this.SendPropertyChanged("StartTime");
                    this.OnStartTimeChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_FinishTime", DbType = "SmallDateTime")]

        public System.Nullable<System.DateTime> FinishTime
        {
            get
            {
                return this._FinishTime;
            }
            internal set
            {
                if ((this._FinishTime != value))
                {
                    this.OnFinishTimeChanging(value);
                    this.SendPropertyChanging();
                    this._FinishTime = value;
                    this.SendPropertyChanged("FinishTime");
                    this.OnFinishTimeChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_LastActiveTime", DbType = "SmallDateTime")]

        public System.DateTime LastActiveTime
        {
            get
            {
                return this._LastActiveTime;
            }
            internal set
            {
                if ((this._LastActiveTime != value))
                {
                    this.OnLastActiveTimeChanging(value);
                    this.SendPropertyChanging();
                    this._LastActiveTime = value;
                    this.SendPropertyChanged("LastActiveTime");
                    this.OnLastActiveTimeChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Name = "LastStage", Storage = "_LastStageName", DbType = "NVarChar(50) NOT NULL", CanBeNull = false)]

        public string LastStageDisplayName
        {
            get
            {
                return this._LastStageName;
            }
            internal set
            {
                if ((this._LastStageName != value))
                {
                    this.OnLastStageChanging(value);
                    this.SendPropertyChanging();
                    this._LastStageName = value;
                    this.SendPropertyChanged("LastStage");
                    this.OnLastStageChanged();
                }
            }
        }

        private string _activeStageDisplayNames;
        [Column(Name = "ActiveStages", Storage = "_activeStageDisplayNames", DbType = "nvarchar(512)", CanBeNull = true)]
        public string ActiveStageDisplayNames
        {
            get { return _activeStageDisplayNames; }
            set
            {
                if (_activeStageDisplayNames != value)
                {
                    SendPropertyChanging();
                    _activeStageDisplayNames = value;
                    SendPropertyChanged("ActiveStageDisplayNames");
                }
            }
        }
	

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Status", DbType = "Int NOT NULL", CanBeNull = false)]

        public WorkflowComponentStatus Status
        {
            get
            {
                return this._Status;
            }
            internal set
            {
                if ((this._Status != value))
                {
                    this.OnStatusChanging(value);
                    this.SendPropertyChanging();
                    this._Status = value;
                    this.SendPropertyChanged("Status");
                    this.OnStatusChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_ThreadSeed", DbType = "smallint not null")]
        internal short ThreadSeed
        {
            get
            {
                return this._ThreadSeed;
            }
            set
            {
                if ((this._ThreadSeed != value))
                {
                    this.OnThreadSeedChanging(value);
                    this.SendPropertyChanging();
                    this._ThreadSeed = value;
                    this.SendPropertyChanged("ThreadSeed");
                    this.OnThreadSeedChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Name = "Properties", Storage = "_PropertiesData", DbType = "nvarchar(1024)")]
        protected string PropertiesData
        {
            get
            {
                return this._PropertiesData;
            }
            set
            {
                if ((this._PropertiesData != value))
                {
                    this.OnPropertiesDataChanging(value);
                    this.SendPropertyChanging();
                    this._PropertiesData = value;
                    this.SendPropertyChanged("PropertiesData");
                    this.OnPropertiesDataChanged();
                }
            }
        }

        [DataMember]
        private string _appData;
        [Column(Name = "AppData", Storage = "_appData", DbType = "nvarchar(2048)", CanBeNull = true)]
        protected override string AppDataStore
        {
            get { return _appData; }
            set
            {
                if (_appData != value)
                {
                    SendPropertyChanging();
                    _appData = value;
                    SendPropertyChanged("AppDataStore");
                }
            }
        }

        //[DataMember]
        //private string _appName;
        //[Column(Name = "AppName", Storage = "_appName", DbType = "nvarchar(50)", CanBeNull = true)]
        //public string AppName
        //{
        //    get { return _appName; }
        //    set
        //    {
        //        if (_appName != value)
        //        {
        //            SendPropertyChanging();
        //            _appName = value;
        //            SendPropertyChanged("AppName");
        //        }
        //    }
        //}

        [DataMember]
        private int _frameCount;
        [Column(Storage = "_frameCount", DbType = "int not null", CanBeNull = false)]
        internal int FrameCount
        {
            get { return _frameCount; }
            private set
            {
                if (_frameCount != value)
                {
                    SendPropertyChanging();
                    _frameCount = value;
                    SendPropertyChanged("FrameCount");
                }
            }
        }

        [DataMember]
        private Guid? _parentProcessId;

        [Column(Storage = "_parentProcessId", DbType = "uniqueidentifier", CanBeNull = true)]
        public Guid? ParentProcessId
        {
            get { return _parentProcessId; }
        }

	

        [global::System.Data.Linq.Mapping.AssociationAttribute(Name = "WFProcess_WFThread", Storage = "_ThreadsInternal", ThisKey = "ProcessId", OtherKey = "ProcessId")]
        [DataMember]
        internal EntitySet<WFThread> ThreadsInternal
        {
            get
            {
                return this._ThreadsInternal;
            }
            set
            {
                this._ThreadsInternal.Assign(value);
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void attach_ThreadsInternal(WFThread entity)
        {
            this.SendPropertyChanging();
            entity.Process = this;
        }

        private void detach_ThreadsInternal(WFThread entity)
        {
            this.SendPropertyChanging();
            entity.Process = null;
        }

        private void Initialize()
        {
            this._ThreadsInternal = new EntitySet<WFThread>(new Action<WFThread>(this.attach_ThreadsInternal), new Action<WFThread>(this.detach_ThreadsInternal));
            OnCreated();
        }

        [global::System.Runtime.Serialization.OnDeserializingAttribute()]
        [global::System.ComponentModel.EditorBrowsableAttribute(EditorBrowsableState.Never)]
        public void OnDeserializing(StreamingContext context)
        {
            this.Initialize();
        }
    }

    [global::System.Data.Linq.Mapping.TableAttribute(Name = "dbo.wf_Threads")]
    [global::System.Runtime.Serialization.DataContractAttribute()]
    public partial class WFThread : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        [DataMember]
        private System.Guid _ProcessId;

        [DataMember]
        private short _ThreadId;

        [DataMember]
        private short _ParentThreadId;

        [DataMember]
        private System.DateTime _CreationTime;

        [DataMember]
        private WorkflowComponentStatus _Status;

        [DataMember]
        private System.Nullable<short> _ParentThreadStep;

        [DataMember]
        private string _PropertiesData;

        private EntitySet<WFStep> _StepsInternal;

        private EntityRef<WFProcess> _Process;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnProcessIdChanging(System.Guid value);
        partial void OnProcessIdChanged();
        partial void OnThreadIdChanging(short value);
        partial void OnThreadIdChanged();
        partial void OnParentThreadIdChanging(short value);
        partial void OnParentThreadIdChanged();
        partial void OnCreationTimeChanging(System.DateTime value);
        partial void OnCreationTimeChanged();
        partial void OnStatusChanging(WorkflowComponentStatus value);
        partial void OnStatusChanged();
        partial void OnParentThreadStepChanging(System.Nullable<short> value);
        partial void OnParentThreadStepChanged();
        partial void OnStepSeedChanging(short value);
        partial void OnStepSeedChanged();
        partial void OnSuspendReasonsChanging(ProcessSuspendingReasons value);
        partial void OnSuspendReasonsChanged();
        partial void OnPropertiesDataChanging(string value);
        partial void OnPropertiesDataChanged();
        #endregion

        public WFThread()
        {
            this.Initialize();
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_ProcessId", DbType = "UniqueIdentifier NOT NULL", IsPrimaryKey = true)]
        internal System.Guid ProcessId
        {
            get
            {
                return this._ProcessId;
            }
            set
            {
                if ((this._ProcessId != value))
                {
                    if (this._Process.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnProcessIdChanging(value);
                    this.SendPropertyChanging();
                    this._ProcessId = value;
                    this.SendPropertyChanged("ProcessId");
                    this.OnProcessIdChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_ThreadId", DbType = "SmallInt NOT NULL", IsPrimaryKey = true)]
        internal short ThreadId
        {
            get
            {
                return this._ThreadId;
            }
            set
            {
                if ((this._ThreadId != value))
                {
                    this.OnThreadIdChanging(value);
                    this.SendPropertyChanging();
                    this._ThreadId = value;
                    this.SendPropertyChanged("ThreadId");
                    this.OnThreadIdChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_ParentThreadId", DbType = "SmallInt")]
        internal short ParentThreadId
        {
            get
            {
                return this._ParentThreadId;
            }
            set
            {
                if ((this._ParentThreadId != value))
                {
                    this.OnParentThreadIdChanging(value);
                    this.SendPropertyChanging();
                    this._ParentThreadId = value;
                    this.SendPropertyChanged("ParentThreadId");
                    this.OnParentThreadIdChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_CreationTime", DbType = "DateTime NOT NULL")]
   
        public System.DateTime CreationTime
        {
            get
            {
                return this._CreationTime;
            }
            internal set
            {
                if ((this._CreationTime != value))
                {
                    this.OnCreationTimeChanging(value);
                    this.SendPropertyChanging();
                    this._CreationTime = value;
                    this.SendPropertyChanged("CreationTime");
                    this.OnCreationTimeChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Status", DbType = "Int NOT NULL", CanBeNull = false)]

        public WorkflowComponentStatus Status
        {
            get
            {
                return this._Status;
            }
            internal set
            {
                if ((this._Status != value))
                {
                    this.OnStatusChanging(value);
                    this.SendPropertyChanging();
                    this._Status = value;
                    this.SendPropertyChanged("Status");
                    this.OnStatusChanged();
                }
            }
        }

        [DataMember]
        private string _appDataString;
        [Column(Storage = "_appDataString", Name = "AppData", DbType = "nvarchar(2048)", CanBeNull = true)]
        protected override string AppDataStore
        {
            get { return _appDataString; }
            set
            {
                if (_appDataString != value)
                {
                    SendPropertyChanging();
                    _appDataString = value;
                    SendPropertyChanged("AppDataStore");
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_ParentThreadStep", DbType = "SmallInt")]
        internal System.Nullable<short> ParentThreadStep
        {
            get
            {
                return this._ParentThreadStep;
            }
            set
            {
                if ((this._ParentThreadStep != value))
                {
                    this.OnParentThreadStepChanging(value);
                    this.SendPropertyChanging();
                    this._ParentThreadStep = value;
                    this.SendPropertyChanged("ParentThreadStep");
                    this.OnParentThreadStepChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Name = "Properties", Storage = "_PropertiesData", DbType = "nvarchar(1024)")]
        protected string PropertiesData
        {
            get
            {
                return this._PropertiesData;
            }
            set
            {
                if ((this._PropertiesData != value))
                {
                    this.OnPropertiesDataChanging(value);
                    this.SendPropertyChanging();
                    this._PropertiesData = value;
                    this.SendPropertyChanged("PropertiesData");
                    this.OnPropertiesDataChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.AssociationAttribute(Name = "WFThread_WFStep", Storage = "_StepsInternal", ThisKey = "ProcessId,ThreadId", OtherKey = "ProcessId,ThreadId")]
        [DataMember]
        internal EntitySet<WFStep> StepsInternal
        {
            get
            {
                return this._StepsInternal;
            }
            set
            {
                this._StepsInternal.Assign(value);
            }
        }

        [global::System.Data.Linq.Mapping.AssociationAttribute(Name = "WFProcess_WFThread", Storage = "_Process", ThisKey = "ProcessId", OtherKey = "ProcessId", IsForeignKey = true, DeleteOnNull = true, DeleteRule = "CASCADE")]
        
        public WFProcess Process
        {
            get
            {
                return this._Process.Entity;
            }
            set
            {
                WFProcess previousValue = this._Process.Entity;
                if (((previousValue != value)
                            || (this._Process.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Process.Entity = null;
                        previousValue.ThreadsInternal.Remove(this);
                    }
                    this._Process.Entity = value;
                    if ((value != null))
                    {
                        value.ThreadsInternal.Add(this);
                        this._ProcessId = value.ProcessId;
                    }
                    else
                    {
                        this._ProcessId = default(System.Guid);
                    }
                    this.SendPropertyChanged("Process");
                }
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void attach_StepsInternal(WFStep entity)
        {
            this.SendPropertyChanging();
            entity.Thread = this;
        }

        private void detach_StepsInternal(WFStep entity)
        {
            this.SendPropertyChanging();
            entity.Thread = null;
        }

        private void Initialize()
        {
            this._StepsInternal = new EntitySet<WFStep>(new Action<WFStep>(this.attach_StepsInternal), new Action<WFStep>(this.detach_StepsInternal));
            this._Process = default(EntityRef<WFProcess>);
            OnCreated();
        }

        [global::System.Runtime.Serialization.OnDeserializingAttribute()]
        [global::System.ComponentModel.EditorBrowsableAttribute(EditorBrowsableState.Never)]
        public void OnDeserializing(StreamingContext context)
        {
            this.Initialize();
        }
    }

    [global::System.Data.Linq.Mapping.TableAttribute(Name = "dbo.wf_Steps")]
    [global::System.Runtime.Serialization.DataContractAttribute()]
    public partial class WFStep : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        [DataMember]
        private System.Guid _ProcessId;

        [DataMember]
        private short _ThreadId;

        [DataMember]
        private short _Sequence;

        [DataMember]
        private string _Stage;

        [DataMember]
        private WorkflowComponentStatus _Status;

        [DataMember]
        private System.DateTime _CreationTime;

        [DataMember]
        private System.Nullable<System.DateTime> _LastModifyTime;

        [DataMember]
        private string _OperatorName;

        [DataMember]
        private System.Nullable<System.DateTime> _StartTime;

        [DataMember]
        private System.Nullable<System.DateTime> _FinishTime;

        [DataMember]
        private string _Data;

        [DataMember]
        private string _Comment;

        [DataMember]
        private string _HintData;

        [DataMember]
        private bool _IsActive;

        private EntityRef<WFThread> _Thread;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnProcessIdChanging(System.Guid value);
        partial void OnProcessIdChanged();
        partial void OnThreadIdChanging(short value);
        partial void OnThreadIdChanged();
        partial void OnSequenceChanging(short value);
        partial void OnSequenceChanged();
        partial void OnStageNameChanging(string value);
        partial void OnStageNameChanged();
        partial void OnStatusChanging(WorkflowComponentStatus value);
        partial void OnStatusChanged();
        partial void OnCreationTimeChanging(System.DateTime value);
        partial void OnCreationTimeChanged();
        partial void OnLastModifyTimeChanging(System.Nullable<System.DateTime> value);
        partial void OnLastModifyTimeChanged();
        partial void OnOperatorNameChanging(string value);
        partial void OnOperatorNameChanged();
        partial void OnStartTimeChanging(System.Nullable<System.DateTime> value);
        partial void OnStartTimeChanged();
        partial void OnFinishTimeChanging(System.Nullable<System.DateTime> value);
        partial void OnFinishTimeChanged();
        partial void OnDataChanging(string value);
        partial void OnDataChanged();
        partial void OnCommentChanging(string value);
        partial void OnCommentChanged();
        partial void OnVersionSeedChanging(short value);
        partial void OnVersionSeedChanged();
        partial void OnHintDataChanging(string value);
        partial void OnHintDataChanged();
        partial void OnIsActiveChanging(bool value);
        partial void OnIsActiveChanged();
        #endregion

        public WFStep()
        {
            this.Initialize();
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_ProcessId", DbType = "UniqueIdentifier NOT NULL", IsPrimaryKey = true)]
        internal System.Guid ProcessId
        {
            get
            {
                return this._ProcessId;
            }
            set
            {
                if ((this._ProcessId != value))
                {
                    if (this._Thread.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnProcessIdChanging(value);
                    this.SendPropertyChanging();
                    this._ProcessId = value;
                    this.SendPropertyChanged("ProcessId");
                    this.OnProcessIdChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_ThreadId", DbType = "SmallInt NOT NULL", IsPrimaryKey = true)]
        internal short ThreadId
        {
            get
            {
                return this._ThreadId;
            }
            set
            {
                if ((this._ThreadId != value))
                {
                    if (this._Thread.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.OnThreadIdChanging(value);
                    this.SendPropertyChanging();
                    this._ThreadId = value;
                    this.SendPropertyChanged("ThreadId");
                    this.OnThreadIdChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Sequence", DbType = "SmallInt NOT NULL", IsPrimaryKey = true)]
        internal short Sequence
        {
            get
            {
                return this._Sequence;
            }
            set
            {
                if ((this._Sequence != value))
                {
                    this.OnSequenceChanging(value);
                    this.SendPropertyChanging();
                    this._Sequence = value;
                    this.SendPropertyChanged("Sequence");
                    this.OnSequenceChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Name = "Stage", Storage = "_Stage", DbType = "NVarChar(50) NOT NULL", CanBeNull = false)]
        public string StageName
        {
            get
            {
                return this._Stage;
            }
            internal set
            {
                if ((this._Stage != value))
                {
                    this.OnStageNameChanging(value);
                    this.SendPropertyChanging();
                    this._Stage = value;
                    this.SendPropertyChanged("StageName");
                    this.OnStageNameChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Status", DbType = "Int NOT NULL", CanBeNull = false)]
        public WorkflowComponentStatus Status
        {
            get
            {
                return this._Status;
            }
            internal set
            {
                if ((this._Status != value))
                {
                    this.OnStatusChanging(value);
                    this.SendPropertyChanging();
                    this._Status = value;
                    this.SendPropertyChanged("Status");
                    this.OnStatusChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_CreationTime", DbType = "SmallDateTime NOT NULL")]
        public System.DateTime CreationTime
        {
            get
            {
                return this._CreationTime;
            }
            internal set
            {
                if ((this._CreationTime != value))
                {
                    this.OnCreationTimeChanging(value);
                    this.SendPropertyChanging();
                    this._CreationTime = value;
                    this.SendPropertyChanged("CreationTime");
                    this.OnCreationTimeChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_LastModifyTime", DbType = "SmallDateTime")]
        public System.Nullable<System.DateTime> LastModifyTime
        {
            get
            {
                return this._LastModifyTime;
            }
            internal set
            {
                if ((this._LastModifyTime != value))
                {
                    this.OnLastModifyTimeChanging(value);
                    this.SendPropertyChanging();
                    this._LastModifyTime = value;
                    this.SendPropertyChanged("LastModifyTime");
                    this.OnLastModifyTimeChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_OperatorName", DbType = "NVarChar(50) NOT NULL")]
        public string OperatorName
        {
            get
            {
                return this._OperatorName;
            }
            internal set
            {
                if ((this._OperatorName != value))
                {
                    this.OnOperatorNameChanging(value);
                    this.SendPropertyChanging();
                    this._OperatorName = value;
                    this.SendPropertyChanged("OperatorName");
                    this.OnOperatorNameChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_StartTime", DbType = "SmallDateTime")]
        public System.Nullable<System.DateTime> StartTime
        {
            get
            {
                return this._StartTime;
            }
            internal set
            {
                if ((this._StartTime != value))
                {
                    this.OnStartTimeChanging(value);
                    this.SendPropertyChanging();
                    this._StartTime = value;
                    this.SendPropertyChanged("StartTime");
                    this.OnStartTimeChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_FinishTime", DbType = "SmallDateTime")]
        public System.Nullable<System.DateTime> FinishTime
        {
            get
            {
                return this._FinishTime;
            }
            internal set
            {
                if ((this._FinishTime != value))
                {
                    this.OnFinishTimeChanging(value);
                    this.SendPropertyChanging();
                    this._FinishTime = value;
                    this.SendPropertyChanged("FinishTime");
                    this.OnFinishTimeChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Data", DbType = "NVarChar(MAX)", UpdateCheck = UpdateCheck.Never)]
        protected string Data
        {
            get
            {
                return this._Data;
            }
            set
            {
                if ((this._Data != value))
                {
                    this.OnDataChanging(value);
                    this.SendPropertyChanging();
                    this._Data = value;
                    this.SendPropertyChanged("Data");
                    this.OnDataChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Comment", DbType = "nvarchar(500)")]
        public string Comment
        {
            get
            {
                return this._Comment;
            }
            internal set
            {
                if ((this._Comment != value))
                {
                    this.OnCommentChanging(value);
                    this.SendPropertyChanging();
                    this._Comment = value;
                    this.SendPropertyChanged("Comment");
                    this.OnCommentChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Name = "Hint", Storage = "_HintData", DbType = "nvarchar(512)")]
        protected string HintData
        {
            get
            {
                return this._HintData;
            }
            set
            {
                if ((this._HintData != value))
                {
                    this.OnHintDataChanging(value);
                    this.SendPropertyChanging();
                    this._HintData = value;
                    this.SendPropertyChanged("HintData");
                    this.OnHintDataChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_IsActive", DbType = "bit not null")]
        public bool IsActive
        {
            get
            {
                return this._IsActive;
            }
            internal set
            {
                if ((this._IsActive != value))
                {
                    this.OnIsActiveChanging(value);
                    this.SendPropertyChanging();
                    this._IsActive = value;
                    this.SendPropertyChanged("IsActive");
                    this.OnIsActiveChanged();
                }
            }
        }

        [DataMember]
        private string _userName;

        [Column(Name = "UserName", Storage = "_userName", DbType = "nvarchar(50)", CanBeNull = true)]
        public string UserName
        {
            get { return _userName; }
            internal set
            {
                if (_userName != value)
                {
                    SendPropertyChanging();
                    _userName = value;
                    SendPropertyChanged("UserName");
                }
            }
        }

        [DataMember]
        private string _userId;

        [Column(Name = "UserId", Storage = "_userId", DbType = "varchar(50)", CanBeNull = true)]
        public string UserId
        {
            get { return _userId; }
            set
            {
                if (_userId != value)
                {
                    SendPropertyChanging();
                    _userId = value;
                    SendPropertyChanged("UserId");
                }
            }
        }
	

        [global::System.Data.Linq.Mapping.AssociationAttribute(Name = "WFThread_WFStep", Storage = "_Thread", ThisKey = "ProcessId,ThreadId", OtherKey = "ProcessId,ThreadId", IsForeignKey = true, DeleteOnNull = true, DeleteRule = "CASCADE")]
        public WFThread Thread
        {
            get
            {
                return this._Thread.Entity;
            }
            set
            {
                WFThread previousValue = this._Thread.Entity;
                if (((previousValue != value)
                            || (this._Thread.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging();
                    if ((previousValue != null))
                    {
                        this._Thread.Entity = null;
                        previousValue.StepsInternal.Remove(this);
                    }
                    this._Thread.Entity = value;
                    if ((value != null))
                    {
                        value.StepsInternal.Add(this);
                        this._ProcessId = value.ProcessId;
                        this._ThreadId = value.ThreadId;
                    }
                    else
                    {
                        this._ProcessId = default(System.Guid);
                        this._ThreadId = default(short);
                    }
                    this.SendPropertyChanged("Thread");
                }
            }
        }

        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        private void Initialize()
        {
            this._Thread = default(EntityRef<WFThread>);
            OnCreated();
        }

        [global::System.Runtime.Serialization.OnDeserializingAttribute()]
        [global::System.ComponentModel.EditorBrowsableAttribute(EditorBrowsableState.Never)]
        public void OnDeserializing(StreamingContext context)
        {
            this.Initialize();
        }
    }


    [global::System.Data.Linq.Mapping.TableAttribute(Name = "dbo.wf_Frames")]
    internal partial class WFFrame : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private System.Guid _ProcessId;

        private int _Sequence;

        private string _StepId;

        private System.Data.Linq.Link<System.Data.Linq.Binary> _UndoData;

        private System.DateTime _CreationTime;

        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnProcessIdChanging(System.Guid value);
        partial void OnProcessIdChanged();
        partial void OnSequenceChanging(int value);
        partial void OnSequenceChanged();
        partial void OnStepIdChanging(string value);
        partial void OnStepIdChanged();
        partial void OnUndoDataChanging(System.Data.Linq.Binary value);
        partial void OnUndoDataChanged();
        partial void OnUndoDataAppChanging(System.Data.Linq.Binary value);
        partial void OnUndoDataAppChanged();
        partial void OnCreationTimeChanging(System.DateTime value);
        partial void OnCreationTimeChanged();
        #endregion

        public WFFrame()
        {
            OnCreated();
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_ProcessId", DbType = "UniqueIdentifier NOT NULL", IsPrimaryKey = true)]
        public System.Guid ProcessId
        {
            get
            {
                return this._ProcessId;
            }
            set
            {
                if ((this._ProcessId != value))
                {
                    this.OnProcessIdChanging(value);
                    this.SendPropertyChanging();
                    this._ProcessId = value;
                    this.SendPropertyChanged("ProcessId");
                    this.OnProcessIdChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_Sequence", DbType = "Int NOT NULL", IsPrimaryKey = true)]
        public int Sequence
        {
            get
            {
                return this._Sequence;
            }
            set
            {
                if ((this._Sequence != value))
                {
                    this.OnSequenceChanging(value);
                    this.SendPropertyChanging();
                    this._Sequence = value;
                    this.SendPropertyChanged("Sequence");
                    this.OnSequenceChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_StepId", DbType = "VarChar(70) ", CanBeNull = true)]
        public string StepId
        {
            get
            {
                return this._StepId;
            }
            set
            {
                if ((this._StepId != value))
                {
                    this.OnStepIdChanging(value);
                    this.SendPropertyChanging();
                    this._StepId = value;
                    this.SendPropertyChanged("StepId");
                    this.OnStepIdChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_UndoData", DbType = "Image NOT NULL", CanBeNull = false, UpdateCheck = UpdateCheck.Never)]
        public System.Data.Linq.Binary UndoData
        {
            get
            {
                return this._UndoData.Value;
            }
            set
            {
                if ((this._UndoData.Value != value))
                {
                    this.OnUndoDataChanging(value);
                    this.SendPropertyChanging();
                    this._UndoData.Value = value;
                    this.SendPropertyChanged("UndoData");
                    this.OnUndoDataChanged();
                }
            }
        }

        [global::System.Data.Linq.Mapping.ColumnAttribute(Storage = "_CreationTime", DbType = "DateTime NOT NULL", CanBeNull = false)]
        public System.DateTime CreationTime
        {
            get
            {
                return this._CreationTime;
            }
            set
            {
                if ((this._CreationTime != value))
                {
                    this.OnCreationTimeChanging(value);
                    this.SendPropertyChanging();
                    this._CreationTime = value;
                    this.SendPropertyChanged("CreationTime");
                    this.OnCreationTimeChanged();
                }
            }
        }

        private string _description;
        [Column(Name = "Description", Storage = "_description", DbType = "nvarchar(500)", CanBeNull = true)]
        public string Description
        {
            get { return _description; }
            set
            {
                if (_description != value)
                {
                    SendPropertyChanging();
                    _description = value;
                    SendPropertyChanged("Description");
                }
            }
        }

        private string _workflowVersion;
        [Column(Name = "WorkflowVersion", Storage = "_workflowVersion", CanBeNull = false, DbType = "varchar(10) not null")]
        public string WorkflowVersion
        {
            get { return _workflowVersion; }
            set
            {
                if (_workflowVersion != value)
                {
                    SendPropertyChanging();
                    _workflowVersion = value;
                    SendPropertyChanged("WorkflowVersion");
                }
            }
        }

        private FrameType _type;
        [Column(Name = "Type", Storage = "_type", DbType = "int not null", CanBeNull = false)]
        public FrameType Type
        {
            get { return _type; }
            set
            {
                if (_type != value)
                {
                    SendPropertyChanging();
                    _type = value;
                    SendPropertyChanged("Type");
                }
            }
        }

        private string _workflowName;
        [Column(Name = "WorkflowName", Storage = "_workflowName", DbType = "nvarchar(50) not null", CanBeNull = false)]
        public string WorkflowName
        {
            get { return _workflowName; }
            set
            {
                if (_workflowName != value)
                {
                    SendPropertyChanging();
                    _workflowName = value;
                    SendPropertyChanged("WorkflowName");
                }
            }
        }

        private string _stageName;
        [Column(Name = "StageName", Storage = "_stageName", DbType = "nvarchar(50) not null", CanBeNull = false)]
        public string StageName
        {
            get { return _stageName; }
            set
            {
                if (_stageName != value)
                {
                    SendPropertyChanging();
                    _stageName = value;
                    SendPropertyChanged("StageName");
                }
            }
        }

        private StageUsage _stageType;
        [Column(Name = "StageType", Storage = "_stageType", DbType = "int not null", CanBeNull = false)]
        public StageUsage StageType
        {
            get { return _stageType; }
            set
            {
                if (_stageType != value)
                {
                    SendPropertyChanging();
                    _stageType = value;
                    SendPropertyChanged("StageType");
                }
            }
        }
	
	
        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

    }

    public enum FrameType
    {
        Normal,
        Bridging
    }
}
